import {fetchInfo, modifyPass, modifyUserInfo, avatar} from '@/services/tenant/TenantUser';
import {message} from 'antd';

export default {
  namespace: 'PUcenter',

  state: {
    userInfo: undefined,
  },

  effects: {
    * avatar({payload, callback}, {call}) {
      const response = yield call(avatar, payload);
      if (response.code === 0) {
        message.success('修改成功').then();
        callback && callback();
      }
    },

    * fetchInfo({payload}, {call, put}) {
      const response = yield call(fetchInfo, payload);
      if (response.code === 0) {
        yield put({
          type: 'chgUserInfo',
          payload: response.data,
        });
      }
    },

    * modifyPass({payload, callback}, {call}) {
      const response = yield call(modifyPass, payload);
      if (response.code === 0) {
        message.success('修改成功').then();
        callback && callback();
      }
    },

    * modifyUserInfo({payload, callback}, {call}) {
      const response = yield call(modifyUserInfo, payload);
      if (response.code === 0) {
        message.success('更新成功').then();
        callback && callback();
      }
    },

  },

  reducers: {
    chgUserInfo(state, action) {
      return {
        ...state,
        userInfo: action.payload,
      };
    },
  },
};
